<?php

namespace app\modules\admin;

use Yii;
use yii\helpers\Url;

/**
 * admin module definition class
 */
class Module extends \yii\base\Module {
    /**
     * {@inheritdoc}
     */
    public $controllerNamespace = 'app\modules\admin\controllers';

    /**
     * {@inheritdoc}
     */
    public function init()
    {
        parent::init();

        // custom initialization code goes here
    }

    public function beforeAction($action)
    {

        $this->layout = 'common';
        $allow_route = [
            '/admin/default/login',
        ];
        if (parent::beforeAction($action)) {
            $route = "/admin/{$action->controller->id}/{$action->id}";
            if (Yii::$app->admin->isGuest && in_array($route, $allow_route) == false) {
                Yii::$app->response->redirect(Url::to('/admin/default/login'));
            }
            Yii::$app->view->params['curent_user'] = Yii::$app->admin->identity;
            return true;
        } else {
            return false;
        }
    }
}
